﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Dashboard.ProductBonus.Business;
using ColumnStyle = Infragistics.Win.UltraWinGrid.ColumnStyle;

namespace Dashboard.ProductBonus
{
    public partial class FormWorkerSchedule : Form
    {
        //private ValueList _valueListShift = new ValueList();
        private ValueList _valueListWorkingShift = new ValueList();
        private ValueList _valueListWorkingShiftWorker = new ValueList();
        private readonly int _preColumnCount = 6;
        public FormWorkerSchedule()
        {
            InitializeComponent();
        }

        private void ultraGridWorder_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            // 自适应列宽
            e.Layout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.None;
            // 是否允许调整列宽
            e.Layout.Override.AllowColSizing = AllowColSizing.Free;
            // 是否允许移动栏位顺序
            e.Layout.Override.AllowColMoving = AllowColMoving.NotAllowed;

            // 设置Grid的Split窗口个数，建议设置为1--不允许Split
            e.Layout.MaxColScrollRegions = 1;
            e.Layout.MaxRowScrollRegions = 1;

            // 冻结列
            e.Layout.UseFixedHeaders = false;

            // 排序
            e.Layout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortSingle;

            // 不允许删除
            e.Layout.Override.AllowDelete = DefaultableBoolean.False;

            // 滚动提示
            e.Layout.Bands[0].ScrollTipField = "Staff";

            e.Layout.Bands[0].Columns["Staff"].CellActivation = Activation.NoEdit;
            e.Layout.Bands[0].Columns["Staff"].Width = 50;

            e.Layout.Bands[0].Columns["StaffName"].CellActivation = Activation.NoEdit;
            e.Layout.Bands[0].Columns["StaffName"].Width = 100;

            e.Layout.Bands[0].Columns["Team"].CellActivation = Activation.NoEdit;
            e.Layout.Bands[0].Columns["Team"].Width = 80;

            e.Layout.Bands[0].Columns["Shift"].CellActivation = Activation.NoEdit;
            e.Layout.Bands[0].Columns["Shift"].Width = 60;

            e.Layout.Bands[0].Columns["JoinDate"].Hidden = true;

            /*e.Layout.Bands[0].Columns["Shift"].CellActivation = Activation.AllowEdit;
            e.Layout.Bands[0].Columns["Shift"].Width = 50;
            e.Layout.Bands[0].Columns["Shift"].Header.Appearance.ForeColor = Color.Red;
            e.Layout.Bands[0].Columns["Shift"].ValueList = this._valueListShift;
            e.Layout.Bands[0].Columns["Shift"].Style = ColumnStyle.DropDown;*/

            var dateTimeFrom = this.dateTimePickerFrom.Value;
            var dateTimeTo = this.dateTimePickerTo.Value;
            var yearFrom = dateTimeFrom.Year;
            var yearTo = dateTimeTo.Year;
            for (int i = 0; i < e.Layout.Bands[0].Columns.Count; i++)
            {
                if (i < 5)
                {
                    continue;
                }
                else
                {
                    e.Layout.Bands[0].Columns[i].Header.Appearance.ForeColor = Color.Red;
                    e.Layout.Bands[0].Columns[i].CellActivation = Activation.AllowEdit;
                    e.Layout.Bands[0].Columns[i].Width = 45;
                    e.Layout.Bands[0].Columns[i].ValueList = this._valueListWorkingShiftWorker;
                    e.Layout.Bands[0].Columns[i].Style = ColumnStyle.DropDown;
                    e.Layout.Bands[0].Columns[i].AutoCompleteMode = Infragistics.Win.AutoCompleteMode.Append;

                    var date = e.Layout.Bands[0].Columns[i].Key;
                    DateTime dateTime = DateTime.ParseExact(date, "yyyy-MM-dd", null);
                    e.Layout.Bands[0].Columns[i].Header.Caption = dateTime.ToString("MM/dd");
                    if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
                    {
                        e.Layout.Bands[0].Columns[i].CellAppearance.BackColor = Color.LightGoldenrodYellow;
                        e.Layout.Bands[0].Columns[i].Header.Appearance.BackColor2 = Color.LightGoldenrodYellow;
                    }

                }
            }
        }

        private void FormWorkingSchedule_Load(object sender, EventArgs e)
        {
            this.comboBoxSettingValues.Items.Clear();
            var businessBase = new BusinessBase();
            var workingShift = businessBase.LoadWorkingShift();
            _valueListWorkingShift.ValueListItems.Clear();
            _valueListWorkingShift.ValueListItems.Add("-1", " ");
            _valueListWorkingShiftWorker.ValueListItems.Clear();
            _valueListWorkingShiftWorker.ValueListItems.Add("-1", " ");
            foreach (DataRow row in workingShift.Rows)
            {
                _valueListWorkingShift.ValueListItems.Add(row["id"], row["id"].ToString() + "-" + row["code"].ToString());
                _valueListWorkingShiftWorker.ValueListItems.Add(row["id"], row["id"].ToString() + "-" + row["code"].ToString());

                this.comboBoxSettingValues.Items.Add(new ComboBoxItem() { Text = row["id"].ToString() + "-" + row["code"].ToString(), Value = row["id"] });

            }
            var teamList = businessBase.LoadTeamList();
            this.comboBoxTeam.Items.Clear();
            this.comboBoxTeam.Items.Add("");
            foreach (DataRow row in teamList.Rows)
            {
                this.comboBoxTeam.Items.Add(row["team"]);
            }
        }

        private void BindTeamGrid()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                ultraGridTeam.DataSource = null;
                ultraGridTeam.ResetDisplayLayout();
                ultraGridTeam.Layouts.Clear();

                var dataTable = GenerateTeamSchema();

                var dateTimeFrom = this.dateTimePickerFrom.Value.Date;
                var dateTimeTo = this.dateTimePickerTo.Value.Date;
                if (dateTimeTo < dateTimeFrom)
                {
                    MessageBox.Show(this, "Date to can not earlier than Date from.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.dateTimePickerTo.Focus();
                    return;
                }
                DateTime dateTime = dateTimeFrom;
                while (true)
                {
                    dataTable.Columns.Add(dateTime.ToString("yyyy-MM-dd"));
                    dateTime = dateTime.AddDays(1);
                    if (dateTime > dateTimeTo)
                    {
                        break;
                    }
                }

                string selectedTeam = this.comboBoxTeam.Text;
                string selectedShift = this.comboBoxShift.Text;

                var scheduleByTeam = new WorkingSchedule().GetScheduleByTeam(selectedTeam, selectedShift,
                                                                             this.dateTimePickerFrom.Value.ToString(
                                                                                 "yyyy-MM-dd"),
                                                                             this.dateTimePickerTo.Value.ToString(
                                                                                 "yyyy-MM-dd"));
                List<string> teamList = new List<string>();
                foreach (DataRow row in scheduleByTeam.Rows)
                {
                    if (!teamList.Contains(row["Team"].ToString() + "|" + row["Shift"].ToString()))
                    {
                        teamList.Add(row["Team"].ToString() + "|" + row["Shift"].ToString());
                    }
                }
                if (string.IsNullOrEmpty(selectedTeam))
                {
                    foreach (var item in this.comboBoxTeam.Items)
                    {
                        if (string.IsNullOrEmpty(item.ToString()))
                        {
                            continue;
                        }

                        DataTable dtShift = new BusinessBase().LoadTeamShiftList(item.ToString());

                        foreach (DataRow row in dtShift.Rows)
                        {
                            if (!teamList.Contains(item.ToString() + "|" + row["Shift"].ToString()))
                            {
                                teamList.Add(item.ToString() + "|" + row["Shift"].ToString());
                            }
                        }
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(selectedShift))
                    {
                        DataTable dtShift = new BusinessBase().LoadTeamShiftList(selectedTeam);
                        foreach (DataRow row in dtShift.Rows)
                        {
                            if (!teamList.Contains(selectedTeam + "|" + row["Shift"].ToString()))
                            {
                                teamList.Add(selectedTeam + "|" + row["Shift"].ToString());
                            }
                        }
                    }
                    else
                    {
                        if (!teamList.Contains(selectedTeam + "|" + selectedShift))
                        {
                            teamList.Add(selectedTeam + "|" + selectedShift);
                        }
                    }
                }

                for (int i = 0; i < teamList.Count; i++)
                {
                    DataRow newRow = dataTable.NewRow();
                    var team = teamList[i].Split('|')[0];
                    var shift = teamList[i].Split('|')[1];

                    DataRow[] rows = scheduleByTeam.Select("Team='" + team + "' AND Shift='" + shift + "'");
                    newRow["Team"] = team;
                    newRow["Shift"] = shift;
                    newRow["WorkerSchedule"] = "Staff";
                    foreach (var row in rows)
                    {
                        newRow[((DateTime)row["WorkingDate"]).ToString("yyyy-MM-dd")] = row["WorkingShift"].ToString();
                    }
                    dataTable.Rows.Add(newRow);
                }

                this.ultraGridTeam.DataSource = dataTable;
                this.ultraGridTeam.DataBind();

                ClearWorkerGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void BindWorkerGrid(string team, string shift)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                var dataTable = GenerateWorkerSchema();

                var dateTimeFrom = this.dateTimePickerFrom.Value.Date;
                var dateTimeTo = this.dateTimePickerTo.Value.Date;
                if (dateTimeTo < dateTimeFrom)
                {
                    MessageBox.Show(this, "Date to can not earlier than Date from.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.dateTimePickerTo.Focus();
                    return;
                }
                DateTime dateTime = dateTimeFrom;
                while (true)
                {
                    dataTable.Columns.Add(dateTime.ToString("yyyy-MM-dd"));
                    dateTime = dateTime.AddDays(1);
                    if (dateTime > dateTimeTo)
                    {
                        break;
                    }
                }
                var workerSchedule = new WorkingSchedule().LoadWorkerSchedule(team, shift, dateTimeFrom, dateTimeTo);
                List<string> staffList = new List<string>();
                foreach (DataRow dataRow in workerSchedule.Rows)
                {
                    var staff = dataRow["StaffNo"].ToString();
                    if (!staffList.Contains(staff))
                    {
                        staffList.Add(staff);
                    }
                }
                foreach (string staff in staffList)
                {
                    DataRow[] rows = workerSchedule.Select("StaffNo='" + staff + "'");
                    var newRow = dataTable.NewRow();
                    newRow["Staff"] = staff;
                    newRow["StaffName"] = rows[0]["StaffName"];
                    newRow["Team"] = rows[0]["Team"];
                    newRow["Shift"] = rows[0]["Shift"];
                    newRow["JoinDate"] = rows[0]["JoinDate"];
                    foreach (var dataRow in rows)
                    {
                        if (dataRow["WorkingDate"] != null && !string.IsNullOrEmpty(dataRow["WorkingDate"].ToString()))
                        {
                            DateTime workingDate = (DateTime)dataRow["WorkingDate"];
                            newRow[workingDate.ToString("yyyy-MM-dd")] = dataRow["WorkingShift"];
                        }
                    }

                    dataTable.Rows.Add(newRow);
                }

                this.ultraGridWorker.DataSource = dataTable;
                this.ultraGridWorker.DataBind();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private DataTable GenerateTeamSchema()
        {
            var dataTable = new DataTable();
            dataTable.Columns.Add("WorkerSchedule");
            dataTable.Columns.Add("Team");
            dataTable.Columns.Add("Shift");
            return dataTable;
        }

        private DataTable GenerateWorkerSchema()
        {
            var dataTable = new DataTable();
            dataTable.Columns.Add("Staff");
            dataTable.Columns.Add("StaffName");
            dataTable.Columns.Add("Team");
            dataTable.Columns.Add("Shift");
            dataTable.Columns.Add("JoinDate");
            return dataTable;
        }

        private void toolStripButtonExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void toolStripButtonSaveTeam_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            try
            {
                this.ultraGridTeam.UpdateData();

                if (this.ultraGridTeam.Rows.Count == 0)
                {
                    MessageBox.Show(this, "No data found in the Team grid.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var result =
                        MessageBox.Show(
                            "The staff schedule by the same conditions will be overwrited, are you sure you want to continue?",
                            "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result != DialogResult.Yes)
                {
                    return;
                }
                var data = new Dictionary<string, Dictionary<string, string>>();
                foreach (var row in this.ultraGridTeam.Rows)
                {
                    string team = row.Cells["Team"].Value.ToString();
                    string shift = row.Cells["Shift"].Value.ToString();

                    var dict = new Dictionary<string, string>();
                    foreach (UltraGridCell cell in row.Cells)
                    {
                        if (cell.Column.Key == "WorkerSchedule" || cell.Column.Key == "Team" || cell.Column.Key == "Shift")
                        {
                            continue;
                        }

                        if (!this.CheckWorkingShift(Convert.ToString(cell.Value)))
                        {
                            MessageBox.Show(this, "Invalid working shift, please change it.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            //cell.Selected = true;
                            cell.Activate();
                            
                            return;
                        }

                        if (cell.OriginalValue != cell.Value || string.IsNullOrEmpty(cell.Value.ToString()))
                        {
                            dict.Add(cell.Column.Key, cell.Value.ToString());
                        }
                    }
                    data.Add(team + "|" + shift, dict);
                }

                new WorkingSchedule().SaveTeamData(data, CommonBusiness.GetCurrentLoginUser());
                ClearWorkerGrid();
                this.Cursor = Cursors.Default;
                MessageBox.Show("Save data successfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private bool CheckWorkingShift(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return true;
            }

            foreach (ValueListItem item in this._valueListWorkingShift.ValueListItems)
            {
                if (item.DataValue.ToString() == value)
                {
                    return true;
                }
            }

            return false;
        }

        private void toolStripButtonFind_Click(object sender, EventArgs e)
        {
            BindTeamGrid();
        }

        private void buttonSet_Click(object sender, EventArgs e)
        {
            var selectedItem = this.comboBoxSettingValues.SelectedItem as ComboBoxItem;
            if (selectedItem == null || string.IsNullOrEmpty(selectedItem.Text))
            {
                MessageBox.Show("Please select the value to set!", "Info", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            //bool updated = false;
            ultraGridTeam.UpdateData();

            if (this.ultraGridTeam.Rows.Count > 0)
            {
                if (MessageBox.Show(this, "Are you sure to update all of the data below?", "Confirm",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show("No data in the grid below!", "Info", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            foreach (var row in this.ultraGridTeam.Rows)
            {
                for (int i = 0; i < row.Cells.Count; i++)
                {
                    if (i < 3)
                    {
                        continue;
                    }
                    var key = row.Cells[i].Column.Key;
                    var dateTime = DateTime.ParseExact(key, "yyyy-MM-dd", null);
                    if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
                    {
                        continue;
                    }
                    row.Cells[i].Value = selectedItem.Value;
                    //row.Cells[i].Text = selectedItem.Text;
                }
            }
            ultraGridTeam.UpdateData();
        }

        private void ultraGridTeam_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            // 自适应列宽
            e.Layout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.None;
            // 是否允许调整列宽
            e.Layout.Override.AllowColSizing = AllowColSizing.Free;
            // 是否允许移动栏位顺序
            e.Layout.Override.AllowColMoving = AllowColMoving.NotAllowed;

            // 设置Grid的Split窗口个数，建议设置为1--不允许Split
            e.Layout.MaxColScrollRegions = 1;
            e.Layout.MaxRowScrollRegions = 1;

            // 冻结列
            e.Layout.UseFixedHeaders = false;

            // 排序
            e.Layout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortSingle;

            // 不允许删除
            e.Layout.Override.AllowDelete = DefaultableBoolean.False;


            e.Layout.Bands[0].Columns["WorkerSchedule"].CellActivation = Activation.NoEdit;
            e.Layout.Bands[0].Columns["WorkerSchedule"].Width = 60;
            e.Layout.Bands[0].Columns["WorkerSchedule"].CellAppearance.TextHAlign = HAlign.Center;
            e.Layout.Bands[0].Columns["WorkerSchedule"].Style = ColumnStyle.Button;
            e.Layout.Bands[0].Columns["WorkerSchedule"].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.Always;
            e.Layout.Bands[0].Columns["WorkerSchedule"].Header.Caption = "";

            e.Layout.Bands[0].Columns["Team"].CellActivation = Activation.NoEdit;
            e.Layout.Bands[0].Columns["Team"].Width = 100;

            e.Layout.Bands[0].Columns["Shift"].CellActivation = Activation.NoEdit;
            e.Layout.Bands[0].Columns["Shift"].Width = 60;

            var dateTimeFrom = this.dateTimePickerFrom.Value;
            var dateTimeTo = this.dateTimePickerTo.Value;
            var yearFrom = dateTimeFrom.Year;
            var yearTo = dateTimeTo.Year;
            for (int i = 0; i < e.Layout.Bands[0].Columns.Count; i++)
            {
                if (i < 3)
                {
                    continue;
                }
                else
                {
                    e.Layout.Bands[0].Columns[i].Header.Appearance.ForeColor = Color.Red;
                    e.Layout.Bands[0].Columns[i].CellActivation = Activation.AllowEdit;
                    e.Layout.Bands[0].Columns[i].Width = 45;
                    e.Layout.Bands[0].Columns[i].Style = ColumnStyle.DropDown;
                    e.Layout.Bands[0].Columns[i].ValueList = this._valueListWorkingShift;
                    e.Layout.Bands[0].Columns[i].AutoCompleteMode = Infragistics.Win.AutoCompleteMode.Append;

                    var date = e.Layout.Bands[0].Columns[i].Key;
                    DateTime dateTime = DateTime.ParseExact(date, "yyyy-MM-dd", null);
                    e.Layout.Bands[0].Columns[i].Header.Caption = dateTime.ToString("MM/dd");

                    if (dateTime.DayOfWeek == DayOfWeek.Saturday || dateTime.DayOfWeek == DayOfWeek.Sunday)
                    {
                        e.Layout.Bands[0].Columns[i].CellAppearance.BackColor = Color.LightGoldenrodYellow;
                        e.Layout.Bands[0].Columns[i].Header.Appearance.BackColor2 = Color.LightGoldenrodYellow;
                    }

                }
            }
        }

        private void ultraGridTeam_ClickCellButton(object sender, CellEventArgs e)
        {
            if (e.Cell.Column.Key == "WorkerSchedule")
            {
                var row = e.Cell.Row;
                var team = row.Cells["Team"].Value.ToString();
                var shift = row.Cells["Shift"].Value.ToString();
                BindWorkerGrid(team, shift);
            }
        }

        private void dateTimePickerFrom_ValueChanged(object sender, EventArgs e)
        {
            BindTeamGrid();
        }

        private void dateTimePickerTo_ValueChanged(object sender, EventArgs e)
        {
            BindTeamGrid();
        }

        private void comboBoxTeam_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.LoadTeamShiftList();

            BindTeamGrid();
        }

        private void LoadTeamShiftList()
        {
            BusinessBase bb = new BusinessBase();
            DataTable result = bb.LoadTeamShiftList(this.comboBoxTeam.Text);

            this.comboBoxShift.Items.Clear();
            this.comboBoxShift.Items.Add("");
            foreach (DataRow row in result.Rows)
            {
                this.comboBoxShift.Items.Add(row["Shift"].ToString());
            }
        }

        private void ClearWorkerGrid()
        {
            this.ultraGridWorker.DataSource = null;
            this.ultraGridWorker.DataBind();
        }

        private void toolStripButtonSaveWorker_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                this.ultraGridWorker.UpdateData();

                if (this.ultraGridWorker.Rows.Count == 0)
                {
                    MessageBox.Show(this, "No data found in the Staff grid!", "Info", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                    return;
                }

                var data = new Dictionary<string, Dictionary<string, string>>();
                foreach (var row in this.ultraGridWorker.Rows)
                {

                    string staff = row.Cells["Staff"].Value.ToString();
                    var dict = new Dictionary<string, string>();
                    foreach (UltraGridCell cell in row.Cells)
                    {
                        if (cell.Column.Key == "Staff" || cell.Column.Key == "StaffName" || cell.Column.Key == "JoinDate"
                            || cell.Column.Key == "Team" || cell.Column.Key == "Shift")
                        {
                            continue;
                        }
                        if (!this.CheckWorkingShift(Convert.ToString(cell.Value)))
                        {
                            MessageBox.Show(this, "Invalid working shift, please change it.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            //cell.Selected = true;
                            cell.Activate();
                            return;
                        }
                        if (cell.OriginalValue != cell.Value || string.IsNullOrEmpty(cell.Value.ToString()))
                        {
                            dict.Add(cell.Column.Key, cell.Value.ToString());
                        }
                    }
                    data.Add(staff, dict);
                }

                new WorkingSchedule().SaveWorkerData(data, CommonBusiness.GetCurrentLoginUser());
                this.Cursor = Cursors.Default;
                MessageBox.Show("Save data successfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void ultraGridWorker_BeforeCellListDropDown(object sender, CancelableCellEventArgs e)
        {
            var joinDate = DateTime.Parse(e.Cell.Row.Cells["JoinDate"].Value.ToString());
            var date = DateTime.ParseExact(e.Cell.Column.Key, "yyyy-MM-dd", null);
            if (joinDate > date)
            {
                e.Cancel = true;
                MessageBox.Show(
                    "The staff join date is " + joinDate.ToString("yyyy-MM-dd") + ", the working shift can't be set.",
                    "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void comboBoxShift_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindTeamGrid();
        }

    }

    public class ComboBoxItem
    {
        public string Text { get; set; }
        public object Value { get; set; }
        public override string ToString()
        {
            return this.Text;
        }
    }
}
